﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PCR.Base;
using PCR.Logic;

namespace PCR
{
    public partial class DataIOManager : DevComponents.DotNetBar.Office2007Form
    {
        public DataIOManager()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Show open dialog
            OpenFileDialog importDlg = new OpenFileDialog();
            importDlg.Filter = "Excel文件|*.xls";

            if (importDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.textBox1.Text = importDlg.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Length <= 0)
            {
                MessageBox.Show("请选择要导入的文件！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox1.Focus();
                return;
            }

            if (this.checkBox1.Checked)
            {
                IList<IStdCurve> stdCurves = PCRRoot.Instance.IOManager.ImportFromExcel<IStdCurve>(this.textBox1.Text);
                if (stdCurves == null)
                {
                    MessageBox.Show("标准曲线导入失败！\n请检查内容！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    foreach (IStdCurve std in stdCurves)
                    {
                        PCRRoot.Instance.StdCurveManager.Add(std);
                    } 
                    
                    MessageBox.Show("标准曲线导入成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                
                }
            }

            if (this.checkBox2.Checked)
            {
                IList<IVirusType> virusTypes = PCRRoot.Instance.IOManager.ImportFromExcel<IVirusType>(this.textBox1.Text);
                if (virusTypes == null)
                {
                    MessageBox.Show("HPV亚型导入失败！\n请检查内容！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    foreach (IVirusType type in virusTypes)
                    {
                        if (null == PCRRoot.VirusTypeValue(type.Name))
                        {
                            PCRRoot.Instance.VirusTypeManager.Add(type);
                        }
                    }

                    MessageBox.Show("HPV亚型导入成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                
                }
            }

            if (this.checkBox3.Checked)
            {
                IList<IPatientReport> patientReports = PCRRoot.Instance.IOManager.ImportFromExcel<IPatientReport>(this.textBox1.Text);
                if (patientReports == null)
                {
                    MessageBox.Show("病人信息导入失败！\n请检查内容！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    foreach (IPatientReport report in patientReports)
                    {
                        PCRRoot.Instance.PatientManager.Add(report);
                    }

                    MessageBox.Show("病人信息导入成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                
                }
            }
        }
    }
}
